package com.kitty.record.kittyjava.juc;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description
 * @Author SHEN
 * @Date 2021/1/13
 */
public class ThreadMapDemo {

    public static void main(String[] args) {

        //普通Map并发修改会发生java.util.ConcurrentModificationException
        //Map<String,Object> map = new HashMap<>();

        //方式一
        //Map<String,Object> map = Collections.synchronizedMap(new HashMap<>());
        Map<String,Object> map = new Hashtable<>();




        //方式二 使用juc下面的ConcurrentHashMap
        //Map<String,Object> map = new ConcurrentHashMap<>();


        /*for (int i = 1; i <= 10; i++) {
            final int tmp = i;
            new Thread(()->{
                map.put(UUID.randomUUID().toString().substring(0,6),tmp);
                System.out.println("map = " + map);
            },String.valueOf(tmp)).start();
        }*/
    }



}
